const User = require("../models/user");

// @desc    登录
// @route   GET /users
exports.getUsers = async (req, res) => {
	try {
		// 从查询参数中获取搜索条件 token
		const users = await User.find(req.body);
		if (users.length === 0) {
			// 注册
			const users = await User.create(req.body);
			res.status(200).json({
				success: true,
				code: 200,
				token: users.token,
			});
		} else {
			res.status(200).json({
				success: true,
				code: 200,
				data: users,
			});
		}
	} catch (err) {
		res.status(500).json({
			success: false,
			error: "Server Error",
		});
	}
};
